import { fee_record_search } from "../../api/http"
const util = require('../../utils/util.js')
const { formatTime2 } = util
const timeFn = (times)=> {
   let hours = Math.floor(times / 3600)
   let minutes = Math.floor(times % 3600 / 60)
   let seconds = Math.floor(times % 60)
   return `${hours}小时${minutes}分钟${seconds}秒`
}
Page({

  /**
   * 页面的初始数据
   */
  data: {
    vehicle_num: '',
    feeRecords: []
  },
  getInput(e){
    let v = e.detail.value;
    this.setData({
     vehicle_num: v
    })
 },
 async searchFn(){
   let vehicle_num = this.data.vehicle_num ;
   if(vehicle_num){
     await fee_record_search({vehicle_num})
     .then(
       content=>{
          console.log("搜索:",content)
          let {code,result} = content
          if(code == 200) {
            let arr2024 = result.map(item=>{
              let obj = {};
              let str = item.fee_record_money.toString();
              obj.fee_record_money = str.indexOf(".") >  -1 ? str : str + ".00";
              obj.fee_record_id = item.fee_record_id;
              obj.parking_record_id = item.parking_record_id;
              obj.vehicle_num = item.vehicle_num;
              obj.fee_record_status = item.fee_record_status;
              obj.parking_record_enter_time = formatTime2(item.parking_record_enter_time);
              obj.parking_record_leave_time = formatTime2(item.parking_record_leave_time);
              return obj;
          })
          console.log('x',arr2024)
          this.setData({
            feeRecords: arr2024
          })
          }
       }
     )
   }
   else {
      wx.showToast({
        title: '请输入车牌号码',
        icon:'none'
      })
    }
 },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let {vehicle_num} = options;
    if(vehicle_num){
       this.setData({vehicle_num})
       this.searchFn();
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})